package com.example.androidnote.Util;

import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ThumbnailUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DBUtils {
    public NoteDB noteDB;
    public SQLiteDatabase db;
    static public String getTime(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年mm月dd日 hh:mm:ss");
        return sdf.format(new Date());
    }

    static public String getTimeinE(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyymmddhhmmss");
        return sdf.format(new Date());
    }


    static public Bitmap getImg(String uri,int width,int height){
        Bitmap bitmap;
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        bitmap = BitmapFactory.decodeFile(uri,options);
        options.inJustDecodeBounds = false;
        int w = options.outWidth/width;
        int h = options.outHeight/height;
        int c = w<h?w:h;
        c=c<0?1:c;
        options.inSampleSize = c;
        bitmap = BitmapFactory.decodeFile(uri,options);
        bitmap = ThumbnailUtils.extractThumbnail(bitmap,width,height,ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
        return bitmap;
    }

    static Bitmap getVideoImg(String uri,int width,int height,int kind){
        Bitmap bitmap;
        bitmap = ThumbnailUtils.createVideoThumbnail(uri,kind);
        bitmap = ThumbnailUtils.extractThumbnail(bitmap,width,height,ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
        return bitmap;
    }
}
